
// Copyright (C) 2012 Luca Piccioni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//  
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

namespace Derm.Render
{
	/// <summary>
	/// A point light.
	/// </summary>
	public class PointLight : Light
	{
		#region Point Light Information

		/// <summary>
		/// 
		/// </summary>
		[RenderObjectUniformAttribute("Position")]
		public Vertex4f Position;

		/// <summary>
		/// 
		/// </summary>
		[RenderObjectUniformAttribute("FallOff")]
		public Vertex2f FallOff = new Vertex2f(180.0f, 0.0f);

		/// <summary>
		/// The light attenuation.
		/// </summary>
		[RenderObjectUniformAttribute("AttenuationFactors")]
		public Vertex3f Attenuation
		{
			get { return (new Vertex3f(ConstantAttenuation, LinearAttenuation, QuadraticAttenuation)); }
		}

		/// <summary>
		/// Constant attenuation of the point light.
		/// </summary>
		public float ConstantAttenuation = 1.0f;

		/// <summary>
		/// Linear attenuation of the point light.
		/// </summary>
		public float LinearAttenuation;

		/// <summary>
		/// Quadratic attenuation of the point light.
		/// </summary>
		public float QuadraticAttenuation;

		#endregion

		#region Light Overrides

		internal override void UpdateViewState(ModelMatrix lightMatrix, Vertex3f eyePosition, Vertex3f viewVector)
		{
			// Point light
			FallOff.X = 180.0f;
			// Light direction
			Position = lightMatrix * new Vertex4f(0.0f, 0.0f, 0.0f, 1.0f);
		}

		#endregion
	}
}
